<template>
  <div class="container_mine__constructor">
    <div class="container_mine__constructor__top">
      <div class="container_mine__constructor__top__left">
        <img
          :src="userInfo?.headImg"
          alt=""
          v-if="userInfo?.username"
          @click="
            () => {
              if (showBottom) {
                showBottom = false;
              } else {
                showBottom = true;
              }
            }
          "
        />
        <img
          src="../../../image/defaultHeadImg.png"
          alt=""
          style="width: 50rem; height: 50rem"
          v-else
        />

        <div
          class="container_mine__constructor__top__left__text"
          @click="
            () => {
              if (userInfo?.username) {
                router.push('/authentication');
              }
            }
          "
        >
          去认证>
        </div>
      </div>
      <div
        class="container_mine__constructor__top__mid"
        v-if="userInfo?.username"
      >
        <div class="container_mine__constructor__top__mid__doctorName">
          {{ userInfo?.username }}
        </div>
        <div class="container_mine__constructor__top__mid__hospitalName">
          {{ userInfo?.role }}
        </div>
        <div class="container_mine__constructor__top__mid__showMessage">
          {{ userInfo?.hospital }}
        </div>
      </div>
      <div
        v-else
        class="container_mine__constructor__top__mid"
        style="color: #666; font-size: 18rem"
        @click="
          () => {
            router.push('/login');
          }
        "
      >
        立即登录
      </div>
      <div class="container_mine__constructor__top__right">
        <span class="iconfont" @click="isShowCode">&#xe680;</span>
      </div>
    </div>
  </div>

  <ShowCode
    v-if="showCode && userInfo?.username"
    :showCode="showCode"
    @change-code="changeCode"
  />
  <van-popup
    v-model:show="showBottom"
    round
    position="bottom"
    :style="{ height: '30%' }"
  >
    <img :src="demoImg" alt="" style="width: 50rem; height: 50rem" />
    <van-uploader
      v-model="fileList"
      :deletable="false"
      :max-count="1"
      :after-read="afterRead"
    />
  </van-popup>
</template>
<script setup>
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";
import toShowCode from "../../effects/showCode";
import ShowCode from "../../showCode/ShowCode.vue";
import storage from "../../../utils/storage";
const { showCode, isShowCode, changeCode } = toShowCode;
const router = useRouter();
const showBottom = ref(false);
let userInfo = reactive({});
userInfo = storage.getItem("userInfo");
const fileList = ref([
  // Uploader 根据文件后缀来判断是否为图片文件
  // 如果图片 URL 中不包含类型信息，可以添加 isImage 标记来声明
]);
let demoImg = ref("https://fastly.jsdelivr.net/npm/@vant/assets/logo.png");
const afterRead = (file) => {
  // 此时可以自行将文件上传至服务器
  demoImg.value = file.content;
};
</script>
<style lang="scss" scoped>
.container_mine__constructor {
  width: 376rem;
  height: 102rem;
  background-color: #fff;
  box-shadow: 0 5rem 10rem #e0e0e0;
  margin-top: -45rem;
  border-radius: 8rem;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding-top: 10rem;
  box-sizing: border-box;
  z-index: 9;
  &__top {
    display: flex;
    justify-content: space-around;
    &__left {
      display: flex;
      flex-direction: column;
      justify-content: center;
      img {
        width: 59rem;
        height: 59rem;
        border-radius: 50%;
      }
      &__text {
        background-color: #0088dc;
        border-radius: 10rem;
        margin: 0 auto;
        padding: 1rem;
        margin-top: -10rem;
        color: #fff;
      }
    }
    &__mid {
      display: flex;
      flex-wrap: wrap;
      width: 150rem;
      font-size: 13rem;
      color: #919191;
      margin-left: -20rem;
      &__doctorName {
        font-size: 16rem;
        font-weight: bold;
        margin-right: 5rem;
        color: #000;
      }
      &__showMessage {
        width: 150rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
    &__right {
      width: 55rem;
      height: 55rem;
      padding-top: 10rem;
      font-size: 52rem;
      color: #2f54eb;
    }
  }
}
</style>
